<?php
 namespace Home\Controller;
 use Think\Controller;
 class ManagerController extends Controller{
	 public function userLogin(){
		if(empty($_POST)){
			 $this->display('login');
			 return false;
		}
		$userObj= D("User");
		$userData=$userObj->userLogin($_POST);
		if($userData!==false){
			session('userId',$userData['user_id']);
			session("loginStatus",true);
			session("user_name",$userData['user_name']);
			$this->redirect('user/index','',0,'');
		}else{
			 $note=$userObj->lastErrorMessage;
			 $this->gotoNote("登录失败，失败原因:$note","/index.php/Home/Manager/userLogin");
		}
	 }
	 
	 public function userRegiter(){
		 if(empty($_POST)){
			 $this->display('register');
			 return false;
		 }

		 $userObj= D("User");
		 $userId=$userObj->userRegister($_POST);
		 if($userId>0){
			 $this->gotoNote('注册成功',"/index.php/Home/Manager/userLogin");
			 return true;
		 }else{
			 $note=$userObj->lastErrorMessage;
			 $this->gotoNote("注册失败，失败原因:$note","/index.php/Home/Manager/userRegiter");
		 }
		
	 }
	 
	 
	 public function gotoNote($noteString,$url){
		 $this->assign('noteString',$noteString);
		 $this->assign('url',$url);
		 $this->display('Note/note');
	 }
	 
	 public function logout(){
		 session(null);
		 $this->redirect("/");
	 }
 }